<?php
/**
 * Created by PhpStorm.
 * User: mr.lee
 * Date: 2018/3/28
 * Time: 上午8:55
 * 余额变动操作
 */

namespace app\common\controller;
use app\common\model\AuthMenuCharge;
use app\common\model\AuthMenuRoleUser;
use app\common\model\CardMember;
use app\common\model\CardRank;
use app\common\model\CardUserGet;
use think\Controller;
use think\Request;
use think\Session;
use Wechat\Wxobjopen;

class AuthCharge
{

    const  PATH                 = __DIR__;
    public $log                 = true;
    public $noNeedCheckRules    = [];           //不需要检查的路由规则

    public function __construct()
    {
        $this->request      = request();
        $this->param        = $this->request->param();
        $this->module       = $this->request->module();
        $this->controller   = $this->request->controller();
        $this->action       = $this->request->action();
    }


    //存储此账号下的所有模块
    public function login($uid){
        $AuthMenuCharge = new AuthMenuCharge();
        $AuthMenuRoleUser = new AuthMenuRoleUser();
        $list = $AuthMenuRoleUser->where('user_id',$uid)->field('role_id')->select();
        $authidlist = [];
        foreach ($list as $k=>$v){
            $authidlist[] = $v['role_id'];
        }
        $map['id'] = ['in',$authidlist];
        $lists = $AuthMenuCharge->where($map)->field('app,model,action,id')->select();
        $authlist = [];
        foreach ($lists as $k=>$v){
            $authlist[] = $v['app'].'/'.$v['model'].'/'.$v['action'];
        }
        $authlist = implode(",",$authlist);
        Session::set("user_charge_list",$authlist);
    }


    //检查是否能用
    public function checkMenu($path){
        $count      = count(explode('/',$path));
        if($count == 2){
            $module = Request::instance()->module();
            $path   = "$module/$path";
        }
        $authlist = Session::get("user_charge_list");
        $authres = strstr($authlist,$path);
        if ($authres){
            return true;
        }else{
            return true;
        }
    }

    //当前是否能用
    public function authMenu(){

    }


    
}